package com.example.grade;
public class Course {
    private final String code;
    private final String name;
    private final double credit; // 学分

    public Course(String code, String name, double credit) {
    	if (code == null || code.trim().isEmpty())
            throw new IllegalArgumentException("课程编号不能为空");
        if (name == null || name.trim().isEmpty())
            throw new IllegalArgumentException("课程名称不能为空");
        if (credit <= 0)
            throw new IllegalArgumentException("学分必须大于 0");
        this.code = code;
        this.name = name;
        this.credit = credit;
    }

    public String getCode() { return code; }
    public String getName() { return name; }
    public double getCredit() { return credit; }

    @Override
    public String toString() {
        return String.format("Course{code='%s', name='%s', credit=%.1f}", code, name, credit);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Course)) return false;
        return code.equals(((Course) o).code);
    }

    @Override
    public int hashCode() {
        return code.hashCode();
    }
}